#ifndef __WSIMULATOR_CPP__
#define __WSIMULATOR_CPP__

#include "wsimulator.h"

void HandleMessage(struct WServer::MsgHandle::wmsgdata* msg)
{
	int cround = 0;
	if (msg->clientindex > maxconn) {
		delete msg;return;
	}
	switch (msg->type) {
		default:
			return; //don't delete msg!
	}
}


void compilecmd(std::vector<std::string>& plist)
{
	if (plist.size() <= 0) return;
	if (0) ;
	else if (plist[0] == "msg2main") {
	}
	else if (plist[0] == "msg2socket") {
	}
	else if (plist[0] == "msg2mysql") {
	}
	else if (plist[0] == "reload") {
		printf("reload lua.\n");
	}
}

int main(int argc, char *argv[])
{
	moduleindex = MODULE_WSIMULATOR;
	wserInit(moduleindex);
	GData::servermsglength = 1;

	if (argc > 1) {
		std::vector<std::string> plist;
		for (int i = 1;i < argc;i++) {
			plist.push_back(argv[i]);
		}
		compilecmd(plist);
		return 1;
	}

	char cmd[MAX_SIZE];memset(cmd, 0, MAX_SIZE);
	while (true) {
		scanf("%[ a-zA-Z0-9]s", cmd);
		std::vector<std::string> plist;
		int pos;std::string cmdstr = cmd;
		do {
			pos = cmdstr.find(" ");
			if (pos == std::string::npos) {
				plist.push_back(cmdstr);
				break;
			}
			plist.push_back(cmdstr.substr(0, pos));
			cmdstr = cmdstr.substr(pos+1, cmdstr.length()-pos);
		} while (1);
		compilecmd(plist);
		setbuf(stdin, NULL);
		memset(cmd, 0, MAX_SIZE);
		sleep(1);
	}

	wserUninit();
	return 0;
}

#endif //__WSIMULATOR_CPP__
